import { useState } from 'react';

function useStateTest(props) {
  const [ count, setCount ] = useState(0);
  const [ person, setPerson ] = useState({ name: '张三', age: 20});
  const [ personCount, serPersonCount] = useState(() => props.count || 1);

  function handleCount() {
    setCount(count => {
      const newCount = count + 1;
      document.title = newCount;
      return newCount;
    })
  }

  return (
    <div>
      <span>{count}</span>
      <button onClick={handleCount}>+1</button>
      <span>{person.name}-{person.age}</span>
      <button onClick={()=>{setPerson({ ...person, name:'李四' })}}>setPerson</button>
      <span>{personCount}</span>
    </div>
  );
} 

export default useStateTest;
